package com.mushuilingfeng.ddd.user.domain.user.loginfilter;

import com.mushuilingfeng.ddd.user.domain.base.BusinessException;
import com.mushuilingfeng.ddd.user.domain.base.Ii8nCode;
import com.mushuilingfeng.ddd.user.domain.user.IUserLoginFilter;
import com.mushuilingfeng.ddd.user.domain.user.dto.AbstractLoginDto;
import com.mushuilingfeng.ddd.user.domain.user.entity.User;
import com.mushuilingfeng.ddd.user.domain.user.enums.UserStatusEnum;
import com.mushuilingfeng.ddd.framework.AsSpringBean;

/**
 * 用户状态登录过滤器
 *
 * @author 沐水淋风
 * @date 2024/10/3
 */
@AsSpringBean
public class UserStatusLoginFilter implements IUserLoginFilter {
    
    @Override
    public int order() {
        return 1;
    }
    
    @Override
    public void filter(User user, AbstractLoginDto loginParams) {
        if (user.getStatus().equals(UserStatusEnum.LOCK)) {
            throw new BusinessException(Ii8nCode.USER_LOCKED);
        }
        if (user.getStatus().equals(UserStatusEnum.STOP)) {
            throw new BusinessException(Ii8nCode.USER_NOT_EXIST);
        }
    }
    
}
